using System;
using System.Text.RegularExpressions;

namespace DNNContentBuilder
{
    public static class RegExValidator
    {
        #region "Methods"

        public static bool ValidateControl(String TextToValidate, String Regular_Expression,RegexOptions regexOptions)
        {
            Regex expression = buildRegexExpression(Regular_Expression, regexOptions);
            return validateControl(TextToValidate, expression);
        }

        private static Regex buildRegexExpression(String Regular_Expression,RegexOptions regexOptions)
        {
            Regex expression;
            try
            {
                expression = new Regex(Regular_Expression, regexOptions);
            }
            catch
            {
                return null;
            }

            return expression;
        }

        private static bool validateControl(String TextToValidate, Regex Regular_Expression)
        {
            // test text with expression
            if (Regular_Expression.IsMatch(TextToValidate))
            {
                return true;
            }
            else
            {
                // no match
                return false;
            }
        }

        #endregion


    }
}
